#include "common.h"
#include "proc.h"

_RegSet* schedule(_RegSet *prev);
static int n = 0;

extern _RegSet* do_syscall(_RegSet *r);
static _RegSet* do_event(_Event e, _RegSet* r) {
  switch (e.event) {
    case _EVENT_SYSCALL:
      return do_syscall(r);
    case _EVENT_TRAP: 
      Log("Received _EVENT_TRAP event\n");
      return schedule(r);
    case _EVENT_IRQ_TIME: 
    {
      if(n == 20)
      {
        Log("Received _EVENT_IRQ_TIME event\n");
        n = 0;
      }
      else
      {
        n++;
      }      
      return schedule(r);
    }
    default: panic("Unhandled event ID = %d", e.event);
  }
  return NULL;
}

void init_irq(void) {
  _asye_init(do_event);
}
